/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Login.java
 *
 * Created on 27/06/2012, 20:05:27
 */
package skyuff;

import Controle.DAO;
import Controle.DataSource;
import Modelo.Usuario;

/**
 *
 * @author Máctassio
 */
public class Login extends javax.swing.JFrame {

    /** Creates new form Login */
    public Login() {
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        usuarioLabel = new javax.swing.JLabel();
        usuarioTextField = new javax.swing.JTextField();
        senhaLabel = new javax.swing.JLabel();
        senhaTextField = new javax.swing.JPasswordField();
        confirmarButton = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setName("Form"); // NOI18N

        jPanel1.setName("jPanel1"); // NOI18N

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(skyuff.SkyUFFApp.class).getContext().getResourceMap(Login.class);
        usuarioLabel.setText(resourceMap.getString("usuarioLabel.text")); // NOI18N
        usuarioLabel.setName("usuarioLabel"); // NOI18N

        usuarioTextField.setText(resourceMap.getString("usuarioTextField.text")); // NOI18N
        usuarioTextField.setName("usuarioTextField"); // NOI18N
        usuarioTextField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                usuarioTextFieldActionPerformed(evt);
            }
        });

        senhaLabel.setText(resourceMap.getString("senhaLabel.text")); // NOI18N
        senhaLabel.setName("senhaLabel"); // NOI18N

        senhaTextField.setText(resourceMap.getString("senhaTextField.text")); // NOI18N
        senhaTextField.setName("senhaTextField"); // NOI18N

        confirmarButton.setText(resourceMap.getString("confirmarButton.text")); // NOI18N
        confirmarButton.setName("confirmarButton"); // NOI18N
        confirmarButton.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                confirmarButtonMouseClicked(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(usuarioLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 47, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(senhaLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(usuarioTextField)
                            .addComponent(senhaTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 103, Short.MAX_VALUE)))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(48, 48, 48)
                        .addComponent(confirmarButton)))
                .addContainerGap(18, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(53, 53, 53)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(usuarioLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(usuarioTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(senhaLabel)
                    .addComponent(senhaTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(34, 34, 34)
                .addComponent(confirmarButton)
                .addGap(71, 71, 71))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 247, Short.MAX_VALUE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

private void usuarioTextFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_usuarioTextFieldActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_usuarioTextFieldActionPerformed

private void confirmarButtonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_confirmarButtonMouseClicked

   String senha = senhaTextField.getText();
   String cpfUsuario = usuarioTextField.getText();
   DAO dao = new DAO();
   
   Usuario usuario;
   Modelo.Passagem passagem;
   
   usuario = new Usuario();
   usuario.setCpf("1");
   usuario.setNome("1");
   usuario.setSenha("1");
   usuario.setTipo(1);
   dao.gravarUsuario(usuario);
   
   usuario = new Usuario();
   usuario.setCpf("2");
   usuario.setNome("2");
   usuario.setSenha("2");
   usuario.setTipo(2);
   dao.gravarUsuario(usuario);
   
   usuario = new Usuario();
   usuario.setCpf("3");
   usuario.setNome("3");
   usuario.setSenha("3");
   usuario.setTipo(3);
   dao.gravarUsuario(usuario);
   
   passagem = new Modelo.Passagem();
   passagem.setCpfCliente("1");
   passagem.setClasse("A");
   passagem.setCodigo("1");
   passagem.setAssento("A1");
   passagem.setData("01/01/2013");
   passagem.setNumeroVoo("1");
   passagem.setPreco(1000);
   passagem.setReserva(true);
   dao.gravarPassagem(passagem);
   
   
   //tipos:
   //1 - cliente
   //2 - funcionario
   //3 - gerente
   usuario = (Usuario) dao.carregarUsuario(cpfUsuario);
   if(usuario.getSenha().equals(senha)){
       DataSource.usuarioLogado = usuario;
       switch(usuario.getTipo()){
           case 1:
               MenuCliente menucliente = new MenuCliente();
               menucliente.setVisible(true);
               break;
           case 2:
               CadastroCliente cadastrocliente = new CadastroCliente();
               cadastrocliente.setVisible(true);
               break;
           case 3:
               CadastroFuncionario cadastrofuncionario = new CadastroFuncionario();
               cadastrofuncionario.setVisible(true);
               break;
       }
   }
}//GEN-LAST:event_confirmarButtonMouseClicked

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(Login.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Login.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Login.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Login.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new Login().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton confirmarButton;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JLabel senhaLabel;
    private javax.swing.JPasswordField senhaTextField;
    private javax.swing.JLabel usuarioLabel;
    private javax.swing.JTextField usuarioTextField;
    // End of variables declaration//GEN-END:variables
}
